package edu.hit.irlab.coref.resolve;

import java.util.ArrayList;
import java.util.List;

import nlpeap.ml.FeatureDescription;
import nlpeap.ml.OfflineClassifier;
import edu.hit.irlab.coref.PairFeatureExtractor;
import edu.hit.irlab.coref.PairInstance;

/**
 * The resolver use the <i>Binary Classify</i> to
 * score the {@link edu.hit.irlab.coref.PairInstance Instance} 
 * @author chuter
 *
 */
public class BinaryClassifyResolver implements Resolver {
	private OfflineClassifier _model;
	private List<PairFeatureExtractor> _fes;
	
	public BinaryClassifyResolver(List<PairFeatureExtractor> fes,
            OfflineClassifier model) {
        _fes = fes;
        _model = model;
        ArrayList<FeatureDescription> fds = new ArrayList<FeatureDescription>();
        for (PairFeatureExtractor fe : _fes)
            fe.describeFeatures(fds);

        fds.add(PairInstance.FD_POSITIVE);
        _model.setHeader(fds);
	}
	
	/** reset the classifier */
	public void setOfflineClassifier(OfflineClassifier model) { _model = model; }
	/** reset the <i>PairFeature Extractors</i> */
	public void setPairFeatureExtractorList(List<PairFeatureExtractor> fes) { _fes = fes; }

	@Override
	/** resolve all the Mentions */
	public boolean canResolve(PairInstance ins) { return true; }

	@Override
	/** score the Instance */
	public double score(PairInstance inst) {
		inst.clearFeatureValues();
		
		for (PairFeatureExtractor fe: _fes)
            fe.extractFeatures(inst);
        
		return _model.singleInstanceScore(inst);
	}
	
	@Override
	public String toString() {
		return "BinaryClassify "+"Usiing "+_model.getName();
	}
	
	
}
